package com.zxy.demo.spring.mvc;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.google.common.collect.Lists;
import com.zxy.demo.form.User;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mangofactory.swagger.annotations.ApiIgnore;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;

/**
 * HelloController.
 * 
 * Created by zxybird on 2017/10/28.
 */
@Controller
@RequestMapping("/hello")
@Api(value = "hello")// 必须
public class HelloController {

  private static final Logger LOG = LoggerFactory.getLogger(HelloController.class);

  @RequestMapping(value = "/hello",
      // produces = "application/json;charset=UTF-8",
      method = RequestMethod.POST)
  @ResponseBody
  public List<Long> hello(HttpServletRequest request, Model model, @RequestParam List<Long> uidList) {
    LOG.info("In hello(), uidList = {}", uidList);

    String name = request.getParameter("name");
    LOG.info("In hello(), name = {}. 7", name);
    LOG.info("In hello(), name = {}. 7", name);
    model.addAttribute("name", name);
    return uidList;
  }

  @ApiOperation(value = "ping",
      httpMethod = "GET")
  @RequestMapping("/ping")
  public String ping(HttpServletRequest request, Model model) {
    String name = request.getParameter("name");
    LOG.info("In ping(), name = {}. 7", name);
    model.addAttribute("name", name);
    return "hello";
  }

  @RequestMapping(value = "/login",
      method = RequestMethod.POST)
  @ApiOperation(value = "登陆",
      httpMethod = "POST") // value可以写中文
  public List<User> login(@ApiIgnore ModelMap modelMap // @apiignore表示忽略这个参数的输入，当然我们不需要客户端提交这个值
      , HttpServletRequest request, @ApiParam(required = true,
          value = "用户名") @RequestParam String username,
      @ApiParam(required = true,
          value = "密码") @RequestParam String pwd) {

    return Lists.newArrayList(new User());

  }

}
